﻿#region
/*******************************************************************************
** File Name:		    FoodAttributeService.cs
** Creator:		        chao.jiang 
** EMail:               chao.jiang 
** Create date:	        
** Latest Modifier:
** Latest Modify date:
** Description:		    
** Modify History:
**
** Code Review:
**
** Version number:       1.0.0
*********************************************************************************/
#endregion
using System;
using System.Collections.Generic;
using System.Text;
using EWineShop.Service.Contracts;
using EWineShop.Service.Model;
using EWineShop.IBatisRepository;
using EWineShop.Respository;
using System.Data;
using EWineShop.Entity;

namespace EWineShop.Service
{
    public class FoodAttributeService : IFoodAttributeService
    {
		 IFoodAttribute foodAttribute = new FoodAttributeRepository();
		 
		 #region  Auto Generation
		 

		public void UpdateByFoodAttributeID (FoodAttributeModel model)
		{
			EFoodAttribute entity = ConvertModelToEntity(model);

            foodAttribute.UpdateByFoodAttributeID(entity);

		}

		public void DeleteByFoodAttributeID (System.Int64 foodAttributeID)
		{
		
            foodAttribute.DeleteByFoodAttributeID(foodAttributeID);

		}
		 
        public FoodAttributeModel GetByFoodAttributeID (System.Int64 foodAttributeID)
        {
        
			EFoodAttribute entity = foodAttribute.GetByFoodAttributeID(foodAttributeID);
			
            FoodAttributeModel model = ConvertEntityToModel(entity);


            return model;
        }
        
	
		public IList<FoodAttributeModel> GetAll ()
		{
			IList<EFoodAttribute> entity = foodAttribute.GetAll();
			
			if (entity == null)
            {
                return null;
            }
            
            IList<FoodAttributeModel> list = new List<FoodAttributeModel>();

            foreach (var item in entity)
            {
                FoodAttributeModel model = ConvertEntityToModel(item);
                list.Add(model);
            }
            return list;   
			
		}
		
		private FoodAttributeModel ConvertEntityToModel(EFoodAttribute entity)
		{
			if (entity == null)
            {
                return null;
            }
			FoodAttributeModel model = new FoodAttributeModel();
                        model.FoodAttributeID = entity.FoodAttributeID;
                        model.Name = entity.Name;
                        model.Remark = entity.Remark;
                        model.CreateTime = entity.CreateTime;
                        model.UpdateTime = entity.UpdateTime;
                        return model;
		}
		
		private EFoodAttribute ConvertModelToEntity(FoodAttributeModel model)
		{
			if (model == null)
            {
                return null;
            }
			EFoodAttribute entity = new EFoodAttribute();
                        entity.FoodAttributeID = model.FoodAttributeID;
                        entity.Name = model.Name;
                        entity.Remark = model.Remark;
                        entity.CreateTime = model.CreateTime;
                        entity.UpdateTime = model.UpdateTime;
                        return entity;
		}
		
		
		
		#endregion
    }
}